from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-03-27 14:02:07.740703
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sun, 27, Mar, 2022
Time: 14:02:13
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.7127
Nobs: 608.000 HQIC: -49.1115
Log likelihood: 7332.68 FPE: 3.63786e-22
AIC: -49.3655 Det(Omega_mle): 3.14111e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.347940 0.066148 5.260 0.000
L1.Burgenland 0.105667 0.040390 2.616 0.009
L1.Kärnten -0.110525 0.021114 -5.235 0.000
L1.Niederösterreich 0.193425 0.084393 2.292 0.022
L1.Oberösterreich 0.117006 0.083127 1.408 0.159
L1.Salzburg 0.259998 0.042809 6.073 0.000
L1.Steiermark 0.039157 0.056517 0.693 0.488
L1.Tirol 0.103737 0.045600 2.275 0.023
L1.Vorarlberg -0.067004 0.040269 -1.664 0.096
L1.Wien 0.017741 0.074031 0.240 0.811
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.053249 0.142068 0.375 0.708
L1.Burgenland -0.038024 0.086747 -0.438 0.661
L1.Kärnten 0.042049 0.045347 0.927 0.354
L1.Niederösterreich -0.202451 0.181252 -1.117 0.264
L1.Oberösterreich 0.454570 0.178533 2.546 0.011
L1.Salzburg 0.283003 0.091943 3.078 0.002
L1.Steiermark 0.112778 0.121383 0.929 0.353
L1.Tirol 0.306002 0.097935 3.125 0.002
L1.Vorarlberg 0.026715 0.086487 0.309 0.757
L1.Wien -0.029074 0.158998 -0.183 0.855
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197848 0.033808 5.852 0.000
L1.Burgenland 0.088513 0.020643 4.288 0.000
L1.Kärnten -0.007137 0.010791 -0.661 0.508
L1.Niederösterreich 0.242836 0.043133 5.630 0.000
L1.Oberösterreich 0.159684 0.042486 3.759 0.000
L1.Salzburg 0.040447 0.021880 1.849 0.065
L1.Steiermark 0.027110 0.028886 0.939 0.348
L1.Tirol 0.082234 0.023306 3.528 0.000
L1.Vorarlberg 0.054058 0.020582 2.627 0.009
L1.Wien 0.116453 0.037837 3.078 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.117893 0.033825 3.485 0.000
L1.Burgenland 0.042429 0.020654 2.054 0.040
L1.Kärnten -0.012916 0.010797 -1.196 0.232
L1.Niederösterreich 0.172633 0.043155 4.000 0.000
L1.Oberösterreich 0.334195 0.042508 7.862 0.000
L1.Salzburg 0.100286 0.021891 4.581 0.000
L1.Steiermark 0.112581 0.028901 3.895 0.000
L1.Tirol 0.089806 0.023318 3.851 0.000
L1.Vorarlberg 0.060555 0.020592 2.941 0.003
L1.Wien -0.017738 0.037857 -0.469 0.639
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.124551 0.063401 1.965 0.049
L1.Burgenland -0.045953 0.038713 -1.187 0.235
L1.Kärnten -0.045306 0.020237 -2.239 0.025
L1.Niederösterreich 0.138142 0.080888 1.708 0.088
L1.Oberösterreich 0.160693 0.079674 2.017 0.044
L1.Salzburg 0.285070 0.041031 6.948 0.000
L1.Steiermark 0.058536 0.054170 1.081 0.280
L1.Tirol 0.158543 0.043706 3.628 0.000
L1.Vorarlberg 0.097416 0.038597 2.524 0.012
L1.Wien 0.071214 0.070956 1.004 0.316
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.074320 0.049522 1.501 0.133
L1.Burgenland 0.024728 0.030238 0.818 0.413
L1.Kärnten 0.053197 0.015807 3.365 0.001
L1.Niederösterreich 0.191558 0.063181 3.032 0.002
L1.Oberösterreich 0.330008 0.062233 5.303 0.000
L1.Salzburg 0.035874 0.032050 1.119 0.263
L1.Steiermark 0.009141 0.042312 0.216 0.829
L1.Tirol 0.120453 0.034138 3.528 0.000
L1.Vorarlberg 0.066060 0.030148 2.191 0.028
L1.Wien 0.096391 0.055424 1.739 0.082
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173208 0.059685 2.902 0.004
L1.Burgenland 0.005010 0.036444 0.137 0.891
L1.Kärnten -0.065921 0.019051 -3.460 0.001
L1.Niederösterreich -0.106564 0.076147 -1.399 0.162
L1.Oberösterreich 0.206749 0.075004 2.756 0.006
L1.Salzburg 0.054735 0.038627 1.417 0.156
L1.Steiermark 0.247100 0.050995 4.846 0.000
L1.Tirol 0.501598 0.041144 12.191 0.000
L1.Vorarlberg 0.064180 0.036335 1.766 0.077
L1.Wien -0.077307 0.066798 -1.157 0.247
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160315 0.066200 2.422 0.015
L1.Burgenland -0.002726 0.040422 -0.067 0.946
L1.Kärnten 0.062768 0.021131 2.970 0.003
L1.Niederösterreich 0.168334 0.084459 1.993 0.046
L1.Oberösterreich -0.056835 0.083192 -0.683 0.494
L1.Salzburg 0.208621 0.042843 4.869 0.000
L1.Steiermark 0.139176 0.056562 2.461 0.014
L1.Tirol 0.057095 0.045635 1.251 0.211
L1.Vorarlberg 0.146975 0.040301 3.647 0.000
L1.Wien 0.119255 0.074089 1.610 0.107
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.390767 0.038974 10.026 0.000
L1.Burgenland -0.004682 0.023798 -0.197 0.844
L1.Kärnten -0.020857 0.012440 -1.677 0.094
L1.Niederösterreich 0.202595 0.049724 4.074 0.000
L1.Oberösterreich 0.230373 0.048978 4.704 0.000
L1.Salzburg 0.036768 0.025223 1.458 0.145
L1.Steiermark -0.015937 0.033300 -0.479 0.632
L1.Tirol 0.089113 0.026867 3.317 0.001
L1.Vorarlberg 0.051077 0.023727 2.153 0.031
L1.Wien 0.043831 0.043619 1.005 0.315
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036345 0.107288 0.170665 0.137414 0.099556 0.079863 0.034170 0.209565
Kärnten 0.036345 1.000000 -0.026621 0.130722 0.048872 0.084894 0.443735 -0.066879 0.089348
Niederösterreich 0.107288 -0.026621 1.000000 0.312804 0.119382 0.273504 0.066572 0.153409 0.292708
Oberösterreich 0.170665 0.130722 0.312804 1.000000 0.212287 0.295637 0.165334 0.136521 0.238475
Salzburg 0.137414 0.048872 0.119382 0.212287 1.000000 0.122943 0.092326 0.104822 0.123830
Steiermark 0.099556 0.084894 0.273504 0.295637 0.122943 1.000000 0.133820 0.107185 0.035730
Tirol 0.079863 0.443735 0.066572 0.165334 0.092326 0.133820 1.000000 0.064133 0.150174
Vorarlberg 0.034170 -0.066879 0.153409 0.136521 0.104822 0.107185 0.064133 1.000000 -0.004420
Wien 0.209565 0.089348 0.292708 0.238475 0.123830 0.035730 0.150174 -0.004420 1.000000